//
//  LCReadTextController.m
//  YinYueTai
//
//  Created by CongCong on 15-7-21.
//  Copyright (c) 2015年 CongCong. All rights reserved.
//

#import "LCReadTextController.h"

@interface LCReadTextController ()
@property (nonatomic) LCReadTextModel *textModel;
@property (nonatomic) UIImageView *image;
@property (nonatomic) UILabel *textLabel;
@property (nonatomic) UITextView *textView;
@end

@implementation LCReadTextController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    [self fetchWebDataWith:kReadTextHeader body:[NSString stringWithFormat:kReadTextBody,self.textID]];
}
- (void)initUI
{
    self.textView = [[UITextView alloc]init];
    self.textView.frame = CGRectMake(0, 64, kScreenSize.width, kScreenSize.height-64);
    self.textView.font = [UIFont fontWithName:@"Heiti SC" size:18];
   
    self.textView.backgroundColor = [UIColor clearColor];
    self.textView.editable = NO;
    self.textView.selectable = NO;
    [self.view addSubview:self.textView];
//    NSArray *familyNames = [UIFont familyNames];
//    for(NSString *familyName in familyNames)
//    {
//        NSLog(@"%@", familyName);
//        NSArray *fontNames = [UIFont    fontNamesForFamilyName:familyName];
//        for(NSString *fontName in fontNames)
//        {
//            NSLog(@"\t%@", fontName);
//        }
//    }
//    self.image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenSize.width, 200)];
//    
//    self.textLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, kScreenSize.width-20, kScreenSize.height)];
//    
//    _textLabel.numberOfLines = 0;
//    _textLabel.backgroundColor = [UIColor grayColor];
//    _textLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:20];
    
}

- (void)initJosnModelWith:(NSDictionary *)dataDict
{
    NSDictionary *dict = dataDict[@"data"];
    self.textModel = [[LCReadTextModel alloc]initWithDictionary:dict error:nil];
    [self addText];
    
}

- (void)addText
{
    NSMutableString *textString = [[NSMutableString alloc]init];
    [textString appendFormat:@"\n%@\n",self.title];
    if (self.textModel.html)
    {
        OCGumboDocument *document = [[OCGumboDocument alloc]initWithHTMLString:self.textModel.html];
        NSArray *rows = document.body.Query(@"article.typo").find(@"p");
        for (OCGumboElement *obj in rows) {
            [textString appendString:[NSString stringWithFormat:@"%@\n        ",obj.text()]];
        }
    }
    
    self.textView.text  = textString;
    
    
//    CGSize contentsize = CGSizeMake(kScreenSize.width-20, 20000.f);
//    UIFont *font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:20] ;
//    
//    CGSize size = [textString sizeWithFont:font constrainedToSize:contentsize lineBreakMode:UILineBreakModeCharacterWrap];
    
   
    
//    self.textLabel.frame = CGRectMake(0, 220, kScreenSize.width, size.height);
//    
//    self.textLabel.text = textString;
//    self.scrollView.contentSize = CGSizeMake(kScreenSize.width, size.height+220);
//    
//    [self.scrollView addSubview:self.textLabel];
   
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
